#include "front/text_normalize.h"

using namespace std;
using namespace ppspeech;

const wregex mcWregexColon(L"\\d+:\\d+(:\\d+)*");

// XX:XX:XX:XX	1:2:3:4 --> 一比二比三比四
// XX:XX:XX		09:09:02 --> 九点零九分零二秒
// XX:XX		09:11 --> 九点十一分
void TextNormalizer::TnReColon(wstring* fpInWsentence, const LanguageEnum fcInLanguage)
{
	wsmatch tWsmatch;

	while(regex_search(*fpInWsentence, tWsmatch, mcWregexColon))
	{
		string tStrReplace = "";
		string tStrColon = wstring2utf8string(tWsmatch[0]);		//匹配到冒号的字符串
		vector<string> tItemColon = StrSplit(tStrColon, ":");	//按冒号分开
		size_t tItemTotal = tItemColon.size();

		int tUnitIndex = tWsmatch.position(0) + tWsmatch.length(0);
		if( tUnitIndex < (*fpInWsentence).length() ) {
			if( (*fpInWsentence).at(tUnitIndex) == L'分' ) {	//匹配项后面有“分”，必定采用点分读法
				tStrReplace = ReplaceMethod(tItemColon, (fcInLanguage==LANG_EN)?RME_en_colon_dianfen:RME_zh_colon_dianfen);
				WstrReplacePosition(fpInWsentence, tWsmatch.position(0), tWsmatch.length(0)+1, utf8string2wstring(tStrReplace));
				continue;
			}
		}

		//超过三项的情况，__:__:__:__，采用比值读法。
		if(tItemTotal > 3) {
			tStrReplace = ReplaceMethod(tItemColon, (fcInLanguage==LANG_EN)?RME_en_colon_ratio:RME_zh_colon_ratio);
		}
		//等于3项的情况，__:__:__，采用点分秒读法。
		else if(tItemTotal == 3) {
			tStrReplace = ReplaceMethod(tItemColon, (fcInLanguage==LANG_EN)?RME_en_colon_dianfenmiao:RME_zh_colon_dianfenmiao);
		}
		//等于2项的情况，__:__，采用点分读法。
		else if(tItemTotal == 2) {
			tStrReplace = ReplaceMethod(tItemColon, (fcInLanguage==LANG_EN)?RME_en_colon_dianfen:RME_zh_colon_dianfen);
		}

		WstrReplacePosition(fpInWsentence, tWsmatch.position(0), tWsmatch.length(0), utf8string2wstring(tStrReplace));
	}
}